import uvicorn
import asyncio


async def app(scope, receive, send):
    assert scope["type"] == "http"
    await send(
        {
            "type": "http.response.start",
            "status": 200,
            "headers": [
                [b"content-type", b"text/plain"],
            ],
        }
    )
    await send(
        {
            "type": "http.response.body",
            "body": b"Hello, world!",
        }
    )


async def main():
    # 异步
    await uvicorn.run(
        "example:app",
        host="127.0.0.1",
        port=5000,
        log_level="info",
        reload=True,
    )
    # 同步 1
    # uvicorn.run( "example:app", host="127.0.0.1", port=5000, log_level="info", debug=True, reload=True, )
    # 同步 2
    # config = uvicorn.Config( "main:app", host="127.0.0.1", port=5000, log_level="info", reload=True, )
    # server = uvicorn.Server(config)
    # server.run()
    # await server.run()
    # await server.serve()


if __name__ == "__main__":
    # 异步
    asyncio.run(main())
